package kr.or.javacafe.cw.web.bokjiro;

import java.sql.ResultSet;
import java.sql.SQLException;

import kr.or.javacafe.cw.common.vo.Resource;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.RowMapper;

public class BokjiroRowMapper implements RowMapper<Resource> {
	
	static Logger logger = LoggerFactory.getLogger(BokjiroRowMapper.class);
	
	
	public Resource mapRow(ResultSet rs, int rowNum) throws SQLException {
		
		Resource res = new Resource();
		
		try {
			
			res.setId( rs.getInt("ID") );
			res.setResourceType( this.stringFilter(rs.getString("RESOURCE_TYPE")) );
			res.setCwType( this.stringFilter(rs.getString("CW_TYPE")) );
			res.setSource( this.stringFilter(rs.getString("SOURCE")) );
			res.setSite( this.stringFilter(rs.getString("SITE")) );
			
			logger.info("리소스정보 : {}", ToStringBuilder.reflectionToString(res));
			
		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error("리소스정보 : {}", ToStringBuilder.reflectionToString(res));
			logger.error(ex.getMessage());
		}
		
		return res;
	}
	
	
	public String stringFilter(String strData) {
		if (StringUtils.isEmpty(strData)) {
			return "";
		} else {
			return strData.trim();
		}
	}
	

	
}
















